package cn.detu.ln.controller;

import cn.detu.ln.entity.Weight;
import cn.detu.ln.service.WeightService;
import cn.detu.ln.utils.PageUtil;
import cn.detu.ln.utils.RestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("weight")
public class WeightController {
    @Autowired
    private WeightService weightService;
    @GetMapping("{url}")
    public RestUtil userGet(@PathVariable String url, Weight weight, PageUtil pageUtil, String search,Float rate){
        switch (url){
            case "selectAll": return weightService.selectAll();
            // 根据课程号模糊查询课程权重信息
            case "queryWeightByCouIdPage":return weightService.queryWeightByCouIdPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            case "weightDelete":return weightService.weightDelete(weight.getId());
            // 根据课程名称模糊查询所有权重信息
            case "queryWeightByPage":return weightService.queryWeightByPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            // 根据学业预警峰值查询课程的权重信息
            case "queryWeightByPredictRate":return weightService.queryWeightByPredictRate(pageUtil.getCurrent(),
                    pageUtil.getRows(),rate);
            // 根据课程id查找单条权重信息
            case "selectWeightByCouId":return  weightService.selectWeightByCouId(weight.getCouId());
        }

        return null;
    }
    @PostMapping("{url}")
    public RestUtil userPost(@PathVariable String url, Weight weight){
        switch (url){
            case "weightUpdate":return weightService.weightUpdate(weight);
            case "weightInsert":return weightService.weightInsert(weight);
        }
        return null;
    }
}
